<template>
  <el-dropdown style="width: 220px; cursor: pointer">
    <span style="font-size: 16px; text-align: center"
      >当前用户: {{ user.userName }}</span
    ><i class="el-icon-arrow-down" style="margin-left: 10px"></i>
    <el-dropdown-menu slot="dropdown" style="font-size: 24px">
      <el-dropdown-item>个人信息</el-dropdown-item>
      <el-dropdown-item>
        <span style="text-decoration: none" @click="logout">
          退出</span
        ></el-dropdown-item
      >
    </el-dropdown-menu>
  </el-dropdown>
</template>
<script>
export default {
  name: "Header",
  props: {
    name: String,
  },
  methods: {
    logout() {
      this.request.post(
        "http://localhost:8081/logout?userName=" + this.user.userName + "&policeId=" + this.user.policeId
      ).then((res) => {
        localStorage.removeItem("user"); //从浏览器的 localStorage 中删除 "user" 键及其对应的值。这通常用于在用户注销时删除存储的用户信息，以确保下次用户访问时他们需要重新登录。
        this.$message.success("退出成功！");
      });
    },
  },
  data() {
    return {
      user: localStorage.getItem("user")
        ? JSON.parse(localStorage.getItem("user"))
        : {},
    };
  },
};
</script>
